package com.skynet.supervision.config.jackson;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class JacksonLocalTime2LongSerializer extends JsonSerializer<LocalDateTime> {
    public static final JacksonLocalTime2LongSerializer INSTANCE = new JacksonLocalTime2LongSerializer();
    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException, JsonProcessingException {
        if (value != null) {
            gen.writeNumber(value.toEpochSecond(ZoneOffset.ofHours(8)));
        }
    }
}
